package bdz.projects.lavender.opsm.utils
{
	import flash.events.EventDispatcher;
	import bdz.common.display.DisplayLoader;
	import flash.utils.Dictionary;
	import flash.events.*;
	/**
	 * ...
	 * @author ...
	 */
	public class ImageCache extends EventDispatcher {
		private static var instance:ImageCache;
		private static var images:Dictionary;
		function ImageCache(se:SingletonEnforcer) {
			
		}
		public static function getInstance():ImageCache {
			if (instance == null) {
				instance = new ImageCache(new SingletonEnforcer());
				instance.initializeCache();
			}
			return instance;
		}
		private function initializeCache():void {
			images = new Dictionary();
		}
		public function getImage(loc:String, onComplete:Function = null):DisplayLoader {
			if (images[loc] == null) {
				images[loc] = new DisplayLoader();
				images[loc].addEventListener(Event.COMPLETE, onComplete);
				images[loc].source = loc;
				images[loc].smoothenBitmap = true;
			}
			return images[loc] as DisplayLoader;
		}
		public function isExisting(loc:String):Boolean {
			return images[loc] != null;
		}
		public function clear():void {
			
		}
	}
	
}
internal class SingletonEnforcer {}